var express = require('express');
var router = express.Router();

function User (name, sex, age) {
  this.name = name;
  this.sex = sex;
  this.age = age;
}

/**
 * GET users listing. 
 * @api {get} 
 * @apiPrivate 
 */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

/**
 * @api {get} /users/:id 用户信息
 * @apiName GetUserInfo
 * @apiVersion 0.0.1
 * @apiGroup User
 * 
 * @apiSampleRequest /users/1
 * 
 * @apiSuccess {String} name 姓名
 * @apiSuccess {String} name.first 名
 * @apiSuccess {String} sex 性别
 * @apiSuccess {Number} age 年龄
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 200 OK
 *  {
 *    "name": {
 *      "first": "张"
 *    },
 *    "sex": "男",
 *    "age": 21
 *  }
 */
router.get('/:id', function(req, res, next) {
  if(req.params.id == 0) next('route');
  else next();
}, function(req, res) {
  var user = new User('张三', '男', 21);
  res.json(user);
})

router.get('/:id', function(req, res, next) {
  res.send('管理员，欢迎您！');
})

/**
 * @api {post} /users/updateuserinfo 更新用户信息
 * @apiName PostUserInfo
 * @apiVersion 0.0.1
 * @apiGroup User
 * 
 * @apiParam {String} userId 用户ID
 * @apiParam {String} newContent 新内容
 * 
 * @apiSuccess {String} userId 用户 ID
 * @apiSuccess {String} newContent 新内容
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 200 OK
 *  {
 *    "userId": "0001",
 *    "newContent": "这是更新后的内容"
 *  }
 */
router.post('/updateuserinfo', function(req, res, next) {
  var update = {};
  update.userId = req.body.userId;
  update.newContent = req.body.newContent;
  res.json(update);
})

module.exports = router;
